package com.techsoul.module.baoli.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.core.pojo.vo.UserVo;
import com.techsoul.common.core.util.ServletUtils;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.common.security.service.TokenService;
import com.techsoul.module.baoli.pojo.param.FinCustomerCreditApplicationSaveParam;
import com.techsoul.module.baoli.pojo.param.FinCustomerCreditApplicationSearchParam;
import com.techsoul.module.baoli.service.IFinCustomerCreditApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 客户授信额度申请列 Controller
 *
 * @author liuen
 * @date 2022-03-28
 */
@Api(tags = "客户授信额度申请列")
@RestController
@RequestMapping("/baoli/finCustomerCreditApplication")
public class FinCustomerCreditApplicationController {

    @Autowired
    private Result result;
    
    @Autowired
    private IFinCustomerCreditApplicationService service;
    @Autowired
    private TokenService tokenService;
    @ApiOperation("新增")
    @Log(title = "客户授信额度申请列", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody FinCustomerCreditApplicationSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "客户授信额度申请列", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "客户授信额度申请列", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:update')")
    @PutMapping
    public Result update(@Valid @RequestBody FinCustomerCreditApplicationSaveParam params) {
        return result.success(this.service.update(params));
    }
    @ApiOperation("审核")
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:platFormprove')")
    @PostMapping("/prove")
    public Result prove(@RequestBody FinCustomerCreditApplicationSaveParam params) {

        return result.success(this.service.prove(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody FinCustomerCreditApplicationSearchParam params) {

        return result.success(this.service.findAll(params));
    }
    @ApiOperation("我批准的列表")
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:search')")
    @PostMapping("/myCompanySearch/{current}/{pageSize}")
    public Result myCompanySearch(@RequestBody FinCustomerCreditApplicationSearchParam params) {
        UserVo user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();

        params.setBaoliSite(user.getSite());
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("我申请的列表")
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:search')")
    @PostMapping("/myAppliedSearch/{current}/{pageSize}")
    public Result myAppliedSearch(@RequestBody FinCustomerCreditApplicationSearchParam params) {
        UserVo user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();

        params.setSite(user.getSite());
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('baoli:finCustomerCreditApplication:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody FinCustomerCreditApplicationSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {

        return result.success(this.service.findAll(params, current, pageSize));
    }

}
